class Solution:
    def maxProfit(self, prices: list) -> int:
        length = len(prices)
        if length <= 1:
            return 0
        prices[0] = [-prices[0], 0, 0]
        for i in range(1, length):
            prices[i] = [max(prices[i-1][2] - prices[i], prices[i-1][0]),
                         max(prices[i-1][0] + prices[i], prices[i-1][1]),
                         max(prices[i-1])]
        return max(prices[-1])


a = Solution()
print(a.maxProfit([1, 2, 3, 0, 2]))
print(a.maxProfit([1, 2]))
print(a.maxProfit([2, 1]))
